import { ref } from 'vue'
import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'
import { setDataBase } from '@/utils/api'

export const useSites = defineStore('sites', () => {
  const tags = ref<any[]>([])
  function setTags(_tags: any[]) {
    return setDataBase(_tags, 'tags').then(() => {
      ElMessage({
        message: '标签已同步',
        type: 'success'
      })
      tags.value = _tags
    })
  }

  const sites = ref<any[]>([])
  function setSites(urls: any[]) {
    return setDataBase(urls, 'sites').then(() => {
      ElMessage({
        message: '收藏已同步',
        type: 'success'
      })
      sites.value = urls
    })
  }

  return { tags, setTags, sites, setSites }
})
